/*     */ package com.cr.web.controller.demo.controller;
/*     */ 
/*     */ import com.cr.common.core.controller.BaseController;
/*     */ import com.cr.common.core.domain.AjaxResult;
/*     */ import com.cr.common.core.page.PageDomain;
/*     */ import com.cr.common.core.page.TableDataInfo;
/*     */ import com.cr.common.core.page.TableSupport;
/*     */ import com.cr.common.core.text.Convert;
/*     */ import com.cr.common.exception.ServiceException;
/*     */ import com.cr.common.utils.MyStringUtils;
import org.apache.commons.lang3.StringUtils;
/*     */ import com.cr.common.utils.poi.ExcelUtil;
/*     */ import com.cr.web.controller.demo.domain.CustomerModel;
/*     */ import com.cr.web.controller.demo.domain.UserOperateModel;
/*     */ import java.util.ArrayList;
/*     */ import java.util.LinkedHashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.springframework.stereotype.Controller;
/*     */ import org.springframework.ui.ModelMap;
/*     */ import org.springframework.web.bind.annotation.GetMapping;
/*     */ import org.springframework.web.bind.annotation.PathVariable;
/*     */ import org.springframework.web.bind.annotation.PostMapping;
/*     */ import org.springframework.web.bind.annotation.RequestMapping;
/*     */ import org.springframework.web.bind.annotation.ResponseBody;
/*     */ import org.springframework.web.multipart.MultipartFile;
/*     */ 
/*     */ @Controller
/*     */ @RequestMapping({"/demo/operate"})
/*     */ public class DemoOperateController extends BaseController {
/*     */   private String prefix;
/*     */   
/*     */   public DemoOperateController() {
/*  36 */     this.prefix = "demo/operate";
/*  40 */     users.put(Integer.valueOf(1), new UserOperateModel(1, "1000001", "测试1", "0", "15888888888", "ry@qq.com", 150.0D, "0"));
/*  41 */     users.put(Integer.valueOf(2), new UserOperateModel(2, "1000002", "测试2", "1", "15666666666", "ry@qq.com", 180.0D, "1"));
/*  42 */     users.put(Integer.valueOf(3), new UserOperateModel(3, "1000003", "测试3", "0", "15666666666", "ry@qq.com", 110.0D, "1"));
/*  43 */     users.put(Integer.valueOf(4), new UserOperateModel(4, "1000004", "测试4", "1", "15666666666", "ry@qq.com", 220.0D, "1"));
/*  44 */     users.put(Integer.valueOf(5), new UserOperateModel(5, "1000005", "测试5", "0", "15666666666", "ry@qq.com", 140.0D, "1"));
/*  45 */     users.put(Integer.valueOf(6), new UserOperateModel(6, "1000006", "测试6", "1", "15666666666", "ry@qq.com", 330.0D, "1"));
/*  46 */     users.put(Integer.valueOf(7), new UserOperateModel(7, "1000007", "测试7", "0", "15666666666", "ry@qq.com", 160.0D, "1"));
/*  47 */     users.put(Integer.valueOf(8), new UserOperateModel(8, "1000008", "测试8", "1", "15666666666", "ry@qq.com", 170.0D, "1"));
/*  48 */     users.put(Integer.valueOf(9), new UserOperateModel(9, "1000009", "测试9", "0", "15666666666", "ry@qq.com", 180.0D, "1"));
/*  49 */     users.put(Integer.valueOf(10), new UserOperateModel(10, "1000010", "测试10", "0", "15666666666", "ry@qq.com", 210.0D, "1"));
/*  50 */     users.put(Integer.valueOf(11), new UserOperateModel(11, "1000011", "测试11", "1", "15666666666", "ry@qq.com", 110.0D, "1"));
/*  51 */     users.put(Integer.valueOf(12), new UserOperateModel(12, "1000012", "测试12", "0", "15666666666", "ry@qq.com", 120.0D, "1"));
/*  52 */     users.put(Integer.valueOf(13), new UserOperateModel(13, "1000013", "测试13", "1", "15666666666", "ry@qq.com", 380.0D, "1"));
/*  53 */     users.put(Integer.valueOf(14), new UserOperateModel(14, "1000014", "测试14", "0", "15666666666", "ry@qq.com", 280.0D, "1"));
/*  54 */     users.put(Integer.valueOf(15), new UserOperateModel(15, "1000015", "测试15", "0", "15666666666", "ry@qq.com", 570.0D, "1"));
/*  55 */     users.put(Integer.valueOf(16), new UserOperateModel(16, "1000016", "测试16", "1", "15666666666", "ry@qq.com", 260.0D, "1"));
/*  56 */     users.put(Integer.valueOf(17), new UserOperateModel(17, "1000017", "测试17", "1", "15666666666", "ry@qq.com", 210.0D, "1"));
/*  57 */     users.put(Integer.valueOf(18), new UserOperateModel(18, "1000018", "测试18", "1", "15666666666", "ry@qq.com", 340.0D, "1"));
/*  58 */     users.put(Integer.valueOf(19), new UserOperateModel(19, "1000019", "测试19", "1", "15666666666", "ry@qq.com", 160.0D, "1"));
/*  59 */     users.put(Integer.valueOf(20), new UserOperateModel(20, "1000020", "测试20", "1", "15666666666", "ry@qq.com", 220.0D, "1"));
/*  60 */     users.put(Integer.valueOf(21), new UserOperateModel(21, "1000021", "测试21", "1", "15666666666", "ry@qq.com", 120.0D, "1"));
/*  61 */     users.put(Integer.valueOf(22), new UserOperateModel(22, "1000022", "测试22", "1", "15666666666", "ry@qq.com", 130.0D, "1"));
/*  62 */     users.put(Integer.valueOf(23), new UserOperateModel(23, "1000023", "测试23", "1", "15666666666", "ry@qq.com", 490.0D, "1"));
/*  63 */     users.put(Integer.valueOf(24), new UserOperateModel(24, "1000024", "测试24", "1", "15666666666", "ry@qq.com", 570.0D, "1"));
/*  64 */     users.put(Integer.valueOf(25), new UserOperateModel(25, "1000025", "测试25", "1", "15666666666", "ry@qq.com", 250.0D, "1"));
/*  65 */     users.put(Integer.valueOf(26), new UserOperateModel(26, "1000026", "测试26", "1", "15666666666", "ry@qq.com", 250.0D, "1"));
/*     */   }
/*     */   
/*     */   private static final Map<Integer, UserOperateModel> users = new LinkedHashMap<>();
/*     */   
/*     */   @GetMapping({"/table"})
/*     */   public String table() {
/*  74 */     return this.prefix + "/table";
/*     */   }
/*     */   
/*     */   @GetMapping({"/other"})
/*     */   public String other() {
/*  83 */     return this.prefix + "/other";
/*     */   }
/*     */   
/*     */   @PostMapping({"/list"})
/*     */   @ResponseBody
/*     */   public TableDataInfo list(UserOperateModel userModel) {
/*  93 */     TableDataInfo rspData = new TableDataInfo();
/*  94 */     List<UserOperateModel> userList = new ArrayList<>(users.values());
/*  96 */     if (StringUtils.isNotEmpty(userModel.getSearchValue())) {
/*  98 */       userList.clear();
/*  99 */       for (Map.Entry<Integer, UserOperateModel> entry : users.entrySet()) {
/* 101 */         if (((UserOperateModel)entry.getValue()).getUserName().equals(userModel.getSearchValue()))
/* 103 */           userList.add(entry.getValue()); 
/*     */       } 
/* 107 */     } else if (StringUtils.isNotEmpty(userModel.getUserName())) {
/* 109 */       userList.clear();
/* 110 */       for (Map.Entry<Integer, UserOperateModel> entry : users.entrySet()) {
/* 112 */         if (((UserOperateModel)entry.getValue()).getUserName().equals(userModel.getUserName()))
/* 114 */           userList.add(entry.getValue()); 
/*     */       } 
/*     */     } 
/* 118 */     PageDomain pageDomain = TableSupport.buildPageRequest();
/* 119 */     if (null == pageDomain.getPageNum() || null == pageDomain.getPageSize()) {
/* 121 */       rspData.setRows(userList);
/* 122 */       rspData.setTotal(userList.size());
/* 123 */       return rspData;
/*     */     } 
/* 125 */     Integer pageNum = Integer.valueOf((pageDomain.getPageNum().intValue() - 1) * 10);
/* 126 */     Integer pageSize = Integer.valueOf(pageDomain.getPageNum().intValue() * 10);
/* 127 */     if (pageSize.intValue() > userList.size())
/* 129 */       pageSize = Integer.valueOf(userList.size()); 
/* 131 */     rspData.setRows(userList.subList(pageNum.intValue(), pageSize.intValue()));
/* 132 */     rspData.setTotal(userList.size());
/* 133 */     return rspData;
/*     */   }
/*     */   
/*     */   @GetMapping({"/add"})
/*     */   public String add(ModelMap mmap) {
/* 142 */     return this.prefix + "/add";
/*     */   }
/*     */   
/*     */   @PostMapping({"/add"})
/*     */   @ResponseBody
/*     */   public AjaxResult addSave(UserOperateModel user) {
/* 152 */     Integer userId = Integer.valueOf(users.size() + 1);
/* 153 */     user.setUserId(userId.intValue());
/* 154 */     return AjaxResult.success(users.put(userId, user));
/*     */   }
/*     */   
/*     */   @PostMapping({"/customer/add"})
/*     */   @ResponseBody
/*     */   public AjaxResult addSave(CustomerModel customerModel) {
/* 164 */     System.out.println(customerModel.toString());
/* 165 */     return AjaxResult.success();
/*     */   }
/*     */   
/*     */   @GetMapping({"/edit/{userId}"})
/*     */   public String edit(@PathVariable("userId") Integer userId, ModelMap mmap) {
/* 174 */     mmap.put("user", users.get(userId));
/* 175 */     return this.prefix + "/edit";
/*     */   }
/*     */   
/*     */   @PostMapping({"/edit"})
/*     */   @ResponseBody
/*     */   public AjaxResult editSave(UserOperateModel user) {
/* 185 */     return AjaxResult.success(users.put(Integer.valueOf(user.getUserId()), user));
/*     */   }
/*     */   
/*     */   @PostMapping({"/export"})
/*     */   @ResponseBody
/*     */   public AjaxResult export(UserOperateModel user) {
/* 195 */     List<UserOperateModel> list = new ArrayList<>(users.values());
/* 196 */     ExcelUtil<UserOperateModel> util = new ExcelUtil(UserOperateModel.class);
/* 197 */     return util.exportExcel(list, "用户数据");
/*     */   }
/*     */   
/*     */   @GetMapping({"/importTemplate"})
/*     */   @ResponseBody
/*     */   public AjaxResult importTemplate() {
/* 207 */     ExcelUtil<UserOperateModel> util = new ExcelUtil(UserOperateModel.class);
/* 208 */     return util.importTemplateExcel("用户数据");
/*     */   }
/*     */   
/*     */   @PostMapping({"/importData"})
/*     */   @ResponseBody
/*     */   public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception {
/* 218 */     ExcelUtil<UserOperateModel> util = new ExcelUtil(UserOperateModel.class);
/* 219 */     List<UserOperateModel> userList = util.importExcel(file.getInputStream());
/* 220 */     String message = importUser(userList, Boolean.valueOf(updateSupport));
/* 221 */     return AjaxResult.success(message);
/*     */   }
/*     */   
/*     */   @PostMapping({"/remove"})
/*     */   @ResponseBody
/*     */   public AjaxResult remove(String ids) {
/* 231 */     Integer[] userIds = Convert.toIntArray(ids);
/* 232 */     for (Integer userId : userIds)
/* 234 */       users.remove(userId); 
/* 236 */     return AjaxResult.success();
/*     */   }
/*     */   
/*     */   @GetMapping({"/detail/{userId}"})
/*     */   public String detail(@PathVariable("userId") Integer userId, ModelMap mmap) {
/* 245 */     mmap.put("user", users.get(userId));
/* 246 */     return this.prefix + "/detail";
/*     */   }
/*     */   
/*     */   @PostMapping({"/clean"})
/*     */   @ResponseBody
/*     */   public AjaxResult clean() {
/* 253 */     users.clear();
/* 254 */     return success();
/*     */   }
/*     */   
/*     */   public String importUser(List<UserOperateModel> userList, Boolean isUpdateSupport) {
/* 266 */     if (MyStringUtils.isNull(userList) || userList.size() == 0)
/* 268 */       throw new ServiceException("导入用户数据不能为空！"); 
/* 270 */     int successNum = 0;
/* 271 */     int failureNum = 0;
/* 272 */     StringBuilder successMsg = new StringBuilder();
/* 273 */     StringBuilder failureMsg = new StringBuilder();
/* 274 */     for (UserOperateModel user : userList) {
/*     */       try {
/* 279 */         boolean userFlag = false;
/* 280 */         for (Map.Entry<Integer, UserOperateModel> entry : users.entrySet()) {
/* 282 */           if (((UserOperateModel)entry.getValue()).getUserName().equals(user.getUserName())) {
/* 284 */             userFlag = true;
/*     */             break;
/*     */           } 
/*     */         } 
/* 288 */         if (!userFlag) {
/* 290 */           Integer userId = Integer.valueOf(users.size() + 1);
/* 291 */           user.setUserId(userId.intValue());
/* 292 */           users.put(userId, user);
/* 293 */           successNum++;
/* 294 */           successMsg.append("<br/>" + successNum + "、用户 " + user.getUserName() + " 导入成功");
/*     */           continue;
/*     */         } 
/* 296 */         if (isUpdateSupport.booleanValue()) {
/* 298 */           users.put(Integer.valueOf(user.getUserId()), user);
/* 299 */           successNum++;
/* 300 */           successMsg.append("<br/>" + successNum + "、用户 " + user.getUserName() + " 更新成功");
/*     */           continue;
/*     */         } 
/* 304 */         failureNum++;
/* 305 */         failureMsg.append("<br/>" + failureNum + "、用户 " + user.getUserName() + " 已存在");
/* 308 */       } catch (Exception e) {
/* 310 */         failureNum++;
/* 311 */         String msg = "<br/>" + failureNum + "、账号 " + user.getUserName() + " 导入失败：";
/* 312 */         failureMsg.append(msg + e.getMessage());
/*     */       } 
/*     */     } 
/* 315 */     if (failureNum > 0) {
/* 317 */       failureMsg.insert(0, "很抱歉，导入失败！共 " + failureNum + " 条数据格式不正确，错误如下：");
/* 318 */       throw new ServiceException(failureMsg.toString());
/*     */     } 
/* 322 */     successMsg.insert(0, "恭喜您，数据已全部导入成功！共 " + successNum + " 条，数据如下：");
/* 324 */     return successMsg.toString();
/*     */   }
/*     */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\classes\com.zip!\com\cr\web\controller\demo\controller\DemoOperateController.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */